<template>
	<view>
		<uni-nav-bar @clickLeft='goback' color="#fff" backgroundColor='' left-icon="back" :border='false'
			statusBar="true"></uni-nav-bar>
		<view class="tit">
			<view class="">
				<view class="">
					欢迎使用
				</view>
				<!-- <image src="../../static/log1.png" mode=""></image> -->
				<image src="/static/logo.png" mode=""></image>
			</view>
			<view class="rigimg">
				<image src="../../static/log2.png" mode=""></image>
			</view>
		</view>

		<view class="content">
			<view class="btns">
				<button v-if="isyes" class="btn" open-type="getPhoneNumber" @getphonenumber="getphonenumber">
					手机号快捷登录
				</button>
				<button v-else class="btn" @click="login">
					手机号快捷登录
				</button>
				<view class="btn b2" @click="gophone">
					验证码登录
				</view>
			</view>
			<view class="tipsre">
				<view class="abssjs" v-if="isshow">
					请先阅读并同意 伊可库用户协议 及 隐私政策
				</view>
				<view class="xy" @click="handlexy">
					<image v-if="isyes" src="../../static/yuana.png" mode=""></image>
					<image v-else src="../../static/yuan.png" mode=""></image>
					<view class="">
						我已阅读并同意<span @click.stop="pagego(1)">伊可库用户协议</span>及<span @click.stop="pagego(2)">隐私政策</span>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		oauthLogin,
	} from '@/common/http.api.js';
	export default {
		data() {
			return {
				isshow: false,
				isyes: false,
			};
		},
		onUnload() {
			uni.removeStorageSync('isHttp')
		},
		methods: {
			gophone() {
				uni.navigateTo({
					url: '/pages/login/phone'
				})
			},
			goback() {
				if (uni.getStorageSync('isHttp')) {
					uni.reLaunch({
						url: '/pages/index/index'
					})
				} else {
					uni.navigateBack()
				}
			},
			handlexy() {
				this.isyes = !this.isyes
				if (this.isyes) {
					this.isshow = false
				}
			},
			pagego(type){
				if(type==1){
					uni.navigateTo({
						url:'/mypage/contactus/useragreement'
					})
				}else{
					uni.navigateTo({
						url:'/mypage/contactus/agreement'
					})
				}
			},
			login() {
				if (this.isyes) {
					this.isshow = false
				} else {
					this.isshow = true
				}
			},
			getphonenumber(e) {
				let that = this
				if (e.detail.errMsg == 'getPhoneNumber:ok') {
					uni.login({
						provider: 'weixin',
						success: function(loginRes) {
							let params = {
								phoneCode: e.detail.code,
								code: loginRes.code, //获取code给后端后端拿code获取token
								inviteId:uni.getStorageSync('userinviteId')?uni.getStorageSync('userinviteId'):''
							}
							uni.showLoading({
								title: '登录中...'
							})
							oauthLogin(params).then(res => {
								if (res.code == 200) {
									uni.setStorageSync('userToken', res.data.token)
									uni.hideLoading()
									if (uni.getStorageSync('isHttp')) {
										uni.reLaunch({
											url: '/pages/index/index'
										})
										
									} else {
										uni.navigateBack()
									}
									uni.removeStorageSync('isHttp')
								}
							})
						}
					});
				}else{
					
				}
			},
		}
	}
</script>

<style lang="scss">
	page {
		background-color: #29A85C;
		height: 100vh;
		overflow: hidden;
	}

	.tit {
		margin: 42rpx;
		font-family: PingFang SC, PingFang SC;
		font-weight: bold;
		font-size: 48rpx;
		color: #000000;
		display: flex;
		justify-content: space-between;

		image {
			margin-top: 18rpx;
			width: 284rpx;
			height: 90rpx;
		}

		.rigimg {
			width: 304rpx;
			height: 503rpx;

			image {
				width: 304rpx;
				height: 503rpx;
			}
		}
	}

	.content {
		position: fixed;
		bottom: 0%;
		width: 750rpx;
		height: 1038rpx;
		background: #FFFFFF;
		border-radius: 80rpx 80rpx 0rpx 0rpx;
		padding: 104rpx 40rpx;
		box-sizing: border-box;
		.btns {
			font-family: PingFang SC, PingFang SC;
			font-weight: 500;
			font-size: 32rpx;
			line-height: 100rpx;
			text-align: center;

			.btn {
				width: 670rpx;
				height: 100rpx;
				background: #000000;
				border-radius: 8rpx 8rpx 8rpx 8rpx;
				margin-bottom: 40rpx;
				color: #FFFFFF;
				line-height: 100rpx;
				font-size: 32rpx;
			}

			.b2 {
				background: #FFFFFF;
				color: #000000;
				border: 1px solid #000;
			}
		}

		.tipsre {
			width: 100%;
			position: fixed;
			bottom: 60rpx;
			width: 580rpx;
			left: 50%;
			transform: translateX(-50%);
			.abssjs {
				width: 580rpx;
				background: rgba(0, 0, 0, 0.8);
				border-radius: 10rpx;
				position: relative;
				padding: 10rpx 30rpx;
				box-sizing: border-box;
				font-size: 26rpx;
				color: #FFFFFF;
				margin: 15rpx auto;
			}

			.abssjs:after {
				content: "";
				border: 12rpx solid rgba(0, 0, 0, 0.8);
				border-top-color: rgba(0, 0, 0, 0.8);
				border-right-color: transparent;
				border-bottom-color: transparent;
				border-left-color: transparent;
				width: 0px;
				height: 0px;
				position: absolute;
				left: 35rpx;
				font-size: 26rpx;
				bottom: -24rpx;
			}

			.xy {
				display: flex;
				align-items: center;
				font-family: PingFang SC, PingFang SC;
				font-weight: 500;
				font-size: 24rpx;
				color: #D1D1D6;
				text-align: center;
				width: 520rpx;
				margin: 0 auto;
				span {
					color: #000;
					margin: 0 6rpx;
				}

				image {
					width: 30rpx;
					height: 30rpx;
					margin-right: 10rpx;
				}
			}
		}

	}
</style>